package com.ssy.jt808.gateway.client.util;

import com.ssy.gaea.util.JsonMapper;
import com.ssy.jt808.gateway.client.constant.T8001ResultConstant;
import com.ssy.jt808.gateway.client.exception.TerminalReplyException;
import com.ssy.jt808.gateway.client.pojo.JtRequestBase;
import com.ssy.jt808.gateway.client.pojo.T8001Reply;

/**
 * @author zeno
 */
public class ReplyVerifyUtil{

  public static void verify( T8001Reply reply, String msg, JtRequestBase requestParam ){
    switch(reply.getResultCode()){
      case T8001ResultConstant.SUCCESS:
      case T8001ResultConstant.ALARM_CONFIRMATION:
        break;
      case T8001ResultConstant.FAILURE:
        throw new TerminalReplyException("{0}，失败。请求参数：{1}",
                                         msg,
                                         JsonMapper.toJsonNode(requestParam));
      case T8001ResultConstant.UNSUPPORTED:
        throw new TerminalReplyException("{0}，不支持。请求参数：{1}",
                                         msg,
                                         JsonMapper.toJsonNode(requestParam));
      case T8001ResultConstant.WRONG_MESSAGE:
        throw new TerminalReplyException("{0}，消息错误。请求参数：{1}",
                                         msg,
                                         JsonMapper.toJsonNode(requestParam));
      default:
        throw new TerminalReplyException("{0}，未知的终端响应码:{1}。请求参数：{2}",
                                         msg,
                                         reply.getResultCode(),
                                         JsonMapper.toJsonNode(requestParam));
    }
  }
}
